home *** CD-ROM | disk | FTP | other *** search
- { control AC via parallel port A or B }
-
- type
- switch_positions = (OFF,ON);
- switch_rec = record
- name : string[15];
- x_location, y_location : integer; {screen coords}
- end;
-
- const
- port_a = $220; { Port locations in the PIO-12 8255 chip. }
- port_b = $221; { Use $378 for LPT1 or $278 for LPT2. }
- port_c = $222; { The stupid compiler can't add constants.}
- control = $223; { To configure the 8255. }
-
- switches : array[0..7] of switch_rec = ( { easier than initializing }
- (name:'Doghouse'; x_location:1; y_location: 1 ),
- (name:'Floodlight 1'; x_location:40; y_location: 1 ),
- (name:'Floodlight 2'; x_location: 1 ; y_location: 6 ),
- (name:'Garage'; x_location:40; y_location: 6 ),
- (name:'Spotlight'; x_location: 1; y_location: 11 ),
- (name:'Radio'; x_location: 40 ; y_location: 11 ),
- (name:'Alarm'; x_location: 1 ; y_location: 16 ),
- (name:'Lock'; x_location: 40 ; y_location: 16 )
- );
- HOME_X = 14; { Keep cursor here during program execution }
- HOME_Y = 20;
-
- var
- switch_state : array [0..7] of switch_positions;
- i : integer;
- switch_byte : byte; { value sent to the output port }
- CH : char;
-
- procedure display_switch_state(switch : integer);
- { Show new switch state on monitor }
- begin
- with switches[i] do begin
- gotoXY(x_location,y_location);
- write(switch,' : ',name);
- gotoXY(x_location + 20, y_location);
- if switch_state[switch] = on then write('ON ')
- else write('OFF');
- end;
- end;
-
- procedure invert_switch(switch : integer);
- { flip a switch from off to on or on to off }
- begin
- { first flip the bit and output the result }
- switch_byte := switch_byte xor (1 shl switch);
- port[port_b] := switch_byte; { see "Port Array" in the manual }
- { now invert the display information }
- if switch_state[switch] = on then
- switch_state[switch] := off else
- switch_state[switch] := on;
- end;
-
- begin
- { Initialize the 8255. Not necessary for LPT1 or LPT2 }
- port[control] := $99; { Port B is output, A & C inputs }
- { Initialize everything else }
- switch_byte := 0;
- ClrScr;
- for i := 0 to 7 do begin
- switch_state[i] := off;
- display_switch_state(i);
- end;
- GotoXY(HOME_X,HOME_Y);
- Write('Press number to change switch; ESC to quit');
- CH := ' ';
- while CH <> chr(27) do begin
- GotoXY(HOME_X -1,HOME_Y);
- read(KBD,CH);
- i := ord(CH) - ord('0');
- if i in [0..7] then begin
- invert_switch(i);
- display_switch_state(i);
- end;
- end;
- end.